#include "syscall.h"
#include "print.c"

#define TICKS	1

int lock;
int otherLock;
int condition;
int otherCondition;

int main()
{
	int i;
	int printMsg[5];

	printString("--> System Test 5 Program 1 <--\n");

	lock = CreateLock();
	condition = CreateCondition();

	printMsg[0] = lock;
	printMsg[1] = condition;
	printf("[Program 1] Lock %d created, Condition %d created.\n", printMsg);

	if (lock == 0) {
		otherLock = 1;
	}
	else {
		otherLock = 0;
	}

	if (condition == 0) {
		otherCondition = 1;
	}
	else {
		otherCondition = 0;
	}

	for (i = 0; i < TICKS; i++) {
		Yield();
	}

	printMsg[0] = lock;
	printf("[Program 1] Trying to acquire lock %d\n", printMsg);
	Acquire(lock);
	printMsg[0] = condition;
	printMsg[1] = lock;
	printf("[Program 1] Trying to wait condition %d with lock %d ... [Program 1 is blocked here forever]\n", printMsg);
	Wait(condition, lock);

	Exit(0);
}
